package com.enhe.gck.fg;

import cn.hutool.core.util.StrUtil;
import com.enhe.gck.communal.PublicConstant;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.pojo.Config;
import com.kuangkie.carbon.panel.CarbonPanel;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.item.ConfigHWANE16627Item; // 模型属性Code

import java.math.BigDecimal;

@Repository(value = "hwane16627366042330866425862")
public class ConfigHWANE16627BNB implements SecondRoundImproveFuncGroup{
	
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		Config config=proRecord.getBean(Config.class);
		if(String.valueOf(CarbonEnumKeyValue.参数配置_类型_甲骨文物料展示名字_jgwwlzsmz).equals(config.getType())){
			PublicMethod.dataPermanent.put(String.valueOf(CarbonEnumKeyValue.参数配置_类型_甲骨文物料展示名字_jgwwlzsmz),config.getValue());
		}
		if(String.valueOf(CarbonEnumKeyValue.参数配置_类型_单袋重量_ddzl).equals(config.getType())){
			PublicMethod.dataPermanent.put(String.valueOf(CarbonEnumKeyValue.参数配置_类型_单袋重量_ddzl),config.getValue());
		}
	}

	public String getConfigValue(long code) {
		Config info=CarbonPanel
				.getRecordQueryFactory(CarbonBaseConstant.参数配置_cspz).getProConJunctionFactory()
				.addEqual(ConfigHWANE16627Item.基本属性组_类型,code).goBack().queryABean(Config.class);
		if(info!=null){
			return info.getValue();
		}
		return null;
	}

	/**
	 * 获取单袋重量
	 * @return
	 */
	public String getConfigValueOneWeight() {
		String value=PublicMethod.dataPermanent.getIfPresent(String.valueOf(CarbonEnumKeyValue.参数配置_类型_单袋重量_ddzl));
		if(value==null){
			value=getConfigValue(CarbonEnumKeyValue.参数配置_类型_单袋重量_ddzl);
			if(value==null){
				value=PublicConstant.config2;
			}
			PublicMethod.dataPermanent.put(String.valueOf(CarbonEnumKeyValue.参数配置_类型_单袋重量_ddzl),value);
		}
		return value;
	}

	/**
	 * 获取甲骨文物料展示名字类型
	 */
	public String getConfigValueNameCode() {
		String nameCode=PublicMethod.dataPermanent.getIfPresent(String.valueOf(CarbonEnumKeyValue.参数配置_类型_甲骨文物料展示名字_jgwwlzsmz));
		if(nameCode==null){
			nameCode=getConfigValue(CarbonEnumKeyValue.参数配置_类型_甲骨文物料展示名字_jgwwlzsmz);
			if(nameCode==null){
				nameCode= PublicConstant.config1;
			}
			PublicMethod.dataPermanent.put(String.valueOf(CarbonEnumKeyValue.参数配置_类型_甲骨文物料展示名字_jgwwlzsmz),nameCode);
		}
		return nameCode;
	}

	//车辆散装下单范围
	public boolean getConfigValue1(double data) {
		boolean flag=true;
		String value=getConfigValue(CarbonEnumKeyValue.参数配置_类型_车辆散装下单范围_clszxdfw);
		if(!StrUtil.isBlank(value)){
			String[] configs=value.split(PublicConstant.Tilde);
			if(configs.length == 2){
				if(!(Double.parseDouble(configs[0])<=data
						&&data<=Double.parseDouble(configs[1]))
				){
					flag=false;
				}
			}
		}
		return flag;
	}

	/**
	 * 产品增值税获取
	 * @param key
	 */
	public BigDecimal getConfigValue2(String key) {
		BigDecimal re=BigDecimal.ZERO;
		if(!StrUtil.isBlank(key)){
			String value=getConfigValue(CarbonEnumKeyValue.参数配置_类型_产品增值税配置_cpzzspz);
			if(!StrUtil.isBlank(value)){
				String[] configs=value.split(PublicConstant.SEMICOLON);
				for (String config : configs) {
					String[] one=config.split(PublicConstant.COMMA);
					if(one.length == 2){
						try {
							if(key.equals(one[0])){
								return new BigDecimal(one[1]);
							}
						}catch (Exception ignored){}
					}
				}
			}
		}
		return re;
	}
}
